<template>
	<view class='paycontent' v-if="IsShow">
		<view class="top">
			<view class='curtitle'>当前订单金额</view>
			<view class='curpay'><text>￥{{current}}</text></view>
		</view>
		<view class="pay">
			<view class='paytitle'>订单支付金额</view>
			<view style="margin-top: 40upx;"><text class='paypoint'>￥</text><text class='paycount'>{{pay}}</text></view>
		</view>
		<view class="paybtn" @click="PayMent">确认支付</view>
	</view>
</template>

<script>
	import api from '@/pages/utils/api.js';
	export default{
		name:'pay',
		data(){
			return{
				current:'',
				pay:'',
				payid:'',
				IsShow:false
			}
		},
		onLoad(e) {
			// this.current = e.payCount;
			// this.pay = e.payCount;
			this.payid = e.id;
		},
		onShow() {
			var vm =this;
			if(uni.getStorageSync('checked_status') == 1){
				uni.navigateTo({
					url: '/pages/index/checked'
				});
				return;
			};
			this.IsShow = true;
			api.getSys({
				
			}).then(data=>{
				if(data.code == 1){
					vm.current = data.data.money;
					vm.pay = data.data.money;
				}
			})
		},
		methods:{
			PayMent:function(){
				var vm = this;
				api.postPay({
					job_id:vm.payid,
					price:vm.pay
				}).then(data=>{ 
					if(data.code == 1){
						uni.requestPayment({
						    provider: 'wxpay',
						    timeStamp: data.data.timeStamp,
						    nonceStr: data.data.nonceStr,
						    package: data.data.package,
						    signType: data.data.signType,
						    paySign: data.data.paySign,
						    success: (res)=>{
								uni.showToast({
									title:'支付成功!'
								});
								setTimeout(()=>{
									uni.reLaunch({
										url: '/pages/index/index'
									})
								},2000)
						    },
						    fail: function (err) {
								uni.showToast({
									icon: 'none',
									title:'支付失败!'
								});
								setTimeout(()=>{
									uni.navigateBack({
									    delta: 1
									});
								},2000)
						    }
						});						
					}
				})
			}
		}
	}
</script>

<style>
	.paycontent{
		text-align: center;
	}
	.top{
		border-bottom: 1px solid #EEEEEE;
		margin: 10% auto 0 auto;
	}
	.curtitle,.paytitle{
		font-size: 32upx;
		color:#666666
	}
	.curpay{
		font-size: 40upx;
		margin: 15upx 0 80upx 0;
	}
	.paypoint{
		font-size: 60upx;
	}
	.paycount{
		border-bottom: 1px solid #ccc;
		width: 240upx;
		display: inline-block;
	}
	.pay{
		margin: 15% auto 0 auto;
	}
	.paybtn{
		background: #F9AC2B;
		width: 80%;
		padding: 15upx 0;
		border-radius: 10upx;
		margin: 100upx auto;
		color:#FFF
	}
</style>
